package com.nbsaas.boot.repository;

import com.nbsaas.boot.entity.Question;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface QuestionRepository extends JpaRepository<Question, Long> {
    
    Page<Question> findByCategory(String category, Pageable pageable);
    
    Page<Question> findByDifficulty(String difficulty, Pageable pageable);
    
    @Query("SELECT q FROM Question q WHERE " +
           "(:category IS NULL OR q.category = :category) AND " +
           "(:difficulty IS NULL OR q.difficulty = :difficulty) AND " +
           "(:keyword IS NULL OR q.title LIKE %:keyword% OR q.description LIKE %:keyword%)")
    Page<Question> search(String category, String difficulty, String keyword, Pageable pageable);
} 